﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_Pledge : ServerBasePacket
    {
        private byte[] _byte = null;

        public S_Pledge( String htmlid, int objid )
        {
            buildPacket( htmlid, objid, 0, "", "", "" );
        }

        public S_Pledge( String htmlid, int objid, String clanname, String olmembers )
        {
            buildPacket( htmlid, objid, 1, clanname, olmembers, "" );
        }

        public S_Pledge( String htmlid, int objid, String clanname,
                String olmembers, String allmembers )
        {

            buildPacket( htmlid, objid, 2, clanname, olmembers, allmembers );
        }

        private void buildPacket( String htmlid, int objid, int type,
                String clanname, String olmembers, String allmembers )
        {

            writeC( Opcodes.S_OPCODE_SHOWHTML );
            writeD( objid );
            writeS( htmlid );
            writeH( type );
            writeH( 0x03 );
            writeS( clanname ); // clanname
            writeS( olmembers ); // clanmember with a space in the end
            writeS( allmembers ); // all clan members names with a space in the
            // end
            // example: "player1 player2 player3 "
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = _bao.ToArray();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] _S_Pledge";
        }
    }
}